/**
 * @program: LeetCode
 * @description: LeetCode : 404. 左叶子之和
 * @author: WXY
 * @create: 2023-01-16 19:55
 * @Version 1.0
 **/
public class Num404_sumOfLeftLeaves {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
        public TreeNode() {
        }
        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    int sum = 0;
    public int sumOfLeftLeaves(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftNum = sumOfLeftLeaves(root.left);
        int rightNum = sumOfLeftLeaves(root.right);
        int mid = 0;
        if (root.left != null && root.left.left == null && root.left.right == null) {
            mid += root.left.val;
        }
        int sum = mid + leftNum + rightNum;
        return sum;
    }
}
